/* 
 * Project: colobok
 * and open the template in the editor.
 * @author: Sviatoslav Mysachenko <svyatoslavik@gmail.com>
 */


var AddPoint = function(map){
    var bindedMapClick= null;
    
    function init(){
        $('#js_addPoint').click(onAddPointBtnClick);       
    }
    
    function onAddPointBtnClick(){        
        bindedMapClick = map.bindEvent('click', onMapClick);
    }
    function onMapClick(e){
        var adv = new Advert();
        adv.lat = e.latLng.lat();
        adv.lng = e.latLng.lng();     
        adv.save();
        $(adv).one('saved', function(){      
           adv.setMap(Core.getComponent('MainMap').getMap());
         //  Core.getComponent('MainMap').add(adv._id, adv);
        });
//        Event.bindOne(adv,'saved',function(){
//           console.log('saved');
//           adv.setMap(map);
//        });
        
//        console.log(e);
//       opetAddPointDialog(e);
       
    }
    function opetAddPointDialog(e){
         $('#js_addPintDialog').css({
            top: $(map.getDiv()).offset().top + e.pixel.y,
            left:$(map.getDiv()).offset().left + $(map.getDiv()).width()/2-$('#js_addPintDialog').width()/2
        }).show();
    }
    init();
}